package com.ruoyi.system.controller;

import java.util.List;
import java.util.Random;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import org.apache.commons.collections4.CollectionUtils;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AHousing;
import com.ruoyi.system.service.IAHousingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 房屋信息Controller
 *
 * @author gf
 * @date 2024-11-23
 */
@RestController
@RequestMapping("/system/aHousing")
public class AHousingController extends BaseController {
    @Autowired
    private IAHousingService aHousingService;

    /**
     * 查询房屋信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AHousing aHousing) {
        startPage();
        List<AHousing> list = aHousingService.selectAHousingList(aHousing);
        return getDataTable(list);
    }

    /**
     * 导出房屋信息列表
     */
    @Log(title = "房屋信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AHousing aHousing) {
        List<AHousing> list = aHousingService.selectAHousingList(aHousing);
        ExcelUtil<AHousing> util = new ExcelUtil<>(AHousing.class);
        util.exportExcel(response, list, "房屋信息数据");
    }

    /**
     * 获取房屋信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(aHousingService.selectAHousingById(id));
    }


    /**
     * 发送短信
     */
    @GetMapping(value = "/sendInforBtn/{id}")
    public AjaxResult sendInforBtn(@PathVariable("id") Long id) {
        return success(aHousingService.selectAHousingBySendInfor(id));
    }

    /**
     * 新增房屋信息
     */
    @Log(title = "房屋信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AHousing aHousing) {
        return toAjax(aHousingService.insertAHousing(aHousing));
    }

    /**
     * 修改房屋信息
     */
    @Log(title = "房屋信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AHousing aHousing) {
        return toAjax(aHousingService.updateAHousing(aHousing));
    }

    /**
     * 删除房屋信息
     */
    @Log(title = "房屋信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(aHousingService.deleteAHousingByIds(ids));
    }

    /**
     * 逻辑删除房屋信息
     */
    @Log(title = "房屋信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/logicDel/{ids}")
    public AjaxResult logicDel(@PathVariable Long[] ids) {
        return toAjax(aHousingService.deleteAHousingByIds(ids));
    }

    /**
     * 获取房屋信息详细信息
     */
    @GetMapping(value = "/updaTime/{id}")
    public AjaxResult updaTime(@PathVariable("id") Long id) {
        return success(aHousingService.updateAHousingUpdaTime(id));
    }

    /**
     * 上传csv文件
     * @param file
     * @return
     */
    @PostMapping(value = "/uploadFile")
    public AjaxResult uploadFile(@RequestParam("file") MultipartFile file,@RequestParam("userId") Long userId)throws Exception {
        return success(aHousingService.updateAHousingUploadFile(file,userId)) ;
    }


}
